const path = require('path');

const htmlWebpackPlugins = require('html-webpack-plugin');

const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');
const webpack = require('webpack');

module.exports = {
    //入口
    entry:{
        app:'./src/index.js'
    },
    //出口
    output:{
        path:path.join(__dirname,'./build'),
        filename:'[name]-[hash:6].js'
    },
    resolve:{
        alias:{
            'utils$':path.resolve(__dirname,'./src/utils/utils.js')  
        },
        extensions:['.js','.json','.scss']
    },
    //loader
    module:{
        rules:[
            {
                test:/\.scss$/,
                use:[{loader:'style-loader'},{loader:'css-loader'},{loader:'sass-loader'}]
            },
            {
                test:/\.jsx?$/,
                use:{
                    loader:'babel-loader',
                    options:{
                        presets:['@babel/preset-react','@babel/preset-env']
                    }
                },
                exclude:/node_modules/
            }
        ]
    },
    //插件
    plugins:[
        new htmlWebpackPlugins({template: './public/index.html'}),
        new ParallelUglifyPlugin({
            uglifyJS:{
              output: {
                comments: false
              },
              warnings: false,
              compress: {
                drop_debugger: true,
                drop_console: true
              }
            }
        }),
        new webpack.DllReferencePlugin({
            context:__dirname,
            manifest:path.join(__dirname,'build/dll','vendors.manifest.json')
        })
    ],
    devServer:{
        port:9090
    },
    // externals:{
    //     'react':'React',
    //     'react-dom':'ReactDOM'
    // }
}